var layer;
var $
var phone;
var account;
layui.use(['layer'],function(){
    layer = layui.layer;
    $=layui.$;

    //获取路由跳转过来的课程·id
    var idArray = window.location.search.split("?");
    account = idArray[1];
    $("#span_account").text(account);

    //获取手机号
    $.ajax({
        url: '/account/getPhoneNumber',
        type: "post",
        dataType: "json",
        data: {"account": account},
        success: function (data) {
            phone=data.data;
            var newphone= data.data.replace(data.data.substr(3, 4),"****")
            $("#span_phone").text(newphone);
        }
    })

});

//获取验证码
$('#getVerification').on('click',function(){
    var verification1=$("#getVerification").text();
    if(verification1=="获取验证码"){
        $.ajax({
            url: '/account/getValidation',
            type: "post",
            dataType: "json",
            data: {"phone": phone},
            success: function (data) {
                //调用计时器
                theTimer();
                $('#nextStep').on('click',function(){
                    //获取input框的验证码
                    var verification=$('#account').val();
                    if(verification==data.data){
                        location.href="/login/Forget_setPwd.html?"+account;
                    }else{
                        layer.msg("请输入正确的验证码",{icon:5});
                    }
                })
            }
        })
    }else{
        layer.msg("请等待计时结束",{icon:5});
    }
})



//计时器
function theTimer(){
    var count;
    var timer = null //timer变量记录定时器setInterval的返回值
    count = 60;
    timer = setInterval(function() {
        count--;
        $('#getVerification').text(count + "秒 重新发送");
        if(count==0){
            $('#getVerification').text("获取验证码");
            clearInterval(timer);
            count = 60;
        }
    }, 1000);
}